package com.coderman.business.converter;

import com.coderman.common.model.business.Product;
import com.coderman.common.vo.business.ProductVO;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangyukang
 * @version 1.0
 * @since 2020/3/17 09:22
 **/
public class ProductConverter {

	/**
	 * 转VOList
	 * @param products
	 * @return
	 */
	public static List<ProductVO> converterToVOList(List<Product> products) {
		List<ProductVO> productVOS = new ArrayList<>();
		if (!CollectionUtils.isEmpty(products)) {
			for (Product product : products) {
				ProductVO productVO = converterToProductVO(product);
				productVOS.add(productVO);
			}
		}
		return productVOS;
	}

	/**
	 * 转VO
	 * @param product
	 * @return
	 */
	public static ProductVO converterToProductVO(Product product) {
		ProductVO productVO = new ProductVO();
		BeanUtils.copyProperties(product, productVO);
		return productVO;
	}

}
